import { usePeFile } from "./hooks/pe.ts";


/**
 * @author tongxin
 * @date 2024/4/22 11:03
 */
export class StringFileInfo {
  SIGNATURE_LENGTH = 28 as const;
  LENGTH = 34 as const;
  STRING_FILE_INFO_MAGIC = "StringFileInfo" as const;

  length?: number;
  valueLength?: number;
  type?: number;
  signature?: string;
  padding?: number;
  offset?: number;

  constructor(byteArray: IByteArray,offset:number) {
    const {calculatePadding} = usePeFile()
    this.offset = offset;

    this.length = byteArray.readWord();
    this.valueLength = byteArray.readWord();
    this.type = byteArray.readWord();
    this.signature = byteArray.readString(this.SIGNATURE_LENGTH);
    if (this.STRING_FILE_INFO_MAGIC != this.signature) {
      throw new Error("StringFileInfo signature error");
    }
    this.padding = calculatePadding(dataReader.getOffset());
  }

  getEndOffset() {
    return this.offset + this.LENGTH + this.padding;
  }
}
